import Statistic, { type IProps } from './fc';
import { defineAmisPlugin, getInputTpl } from '../../base/util';

export default defineAmisPlugin<IProps>(({ amisEditor }) => {
  const { getSchemaTpl } = amisEditor;

  return {
    component: Statistic,
    options: {
      type: 'portal-statistic',
      name: '数据统计组',
      order: 2,
      icon: 'FileImageOutlined',
      description: '数据统计组',
      panelTitle: '数据统计组',
      scaffold: {
        list: [{ width: 200, src: '//www.baidu.com', mode: 'iframe' }]
      },
      panelTabs: [
        {
          title: '常规',
          body: [
            getSchemaTpl('collapseGroup', [
              {
                title: '基本',
                body: [
                  getInputTpl('height', { label: '容器高度', type: 'number' }),
                  getInputTpl('gap', { label: '卡片间隔', type: 'number' })
                ]
              },
              {
                title: '卡片管理',
                body: [
                  {
                    type: 'input-sub-form',
                    name: 'list',
                    multiple: true,
                    addable: true,
                    removable: true,
                    btnLabel: '${src}',
                    mode: 'normal',
                    itemClassName: 'word-break w-full',
                    minLength: 1,
                    draggable: true,
                    form: {
                      title: '设置卡片',
                      body: [
                        {
                          type: 'group',
                          direction: 'vertical',
                          body: [
                            {
                              type: 'select',
                              name: 'mode',
                              value: "${mode||''}",
                              options: [
                                { value: 'iframe', label: 'iframe' },
                                { value: 'qiankun', label: 'qiankun' }
                              ],
                              label: '集成模式'
                            },
                            getInputTpl('src', { label: '卡片地址', visibleOn: "${mode==='iframe'}", required: true }),
                            getInputTpl('microName', {
                              label: '微应用名称',
                              visibleOn: "${mode==='qiankun'}",
                              required: true
                            }),
                            getInputTpl('microEntry', {
                              label: '微应用地址',
                              visibleOn: "${mode==='qiankun'}",
                              required: true
                            }),
                            getInputTpl('microPathname', {
                              label: '微应用路由',
                              visibleOn: "${mode==='qiankun'}",
                              required: true
                            }),
                            {
                              type: 'input-number',
                              name: 'width',
                              label: '卡片宽度',
                              required: true
                            }
                          ]
                        }
                      ]
                    }
                  }
                ]
              }
            ])
          ]
        },
        {
          title: '外观',
          body: [getSchemaTpl('collapseGroup', [...getSchemaTpl('theme:common', { styleName: 'style' })])]
        }
      ]
    }
  };
});
